// e26.groovy

import static java.lang.Math.*

def cycleLength(n) {
    i = 1
    if (n % 2 == 0) return cycleLength(n / 2)
    if (n % 5 == 0) return cycleLength(n / 5)
    while (true) {
        if (10G.pow(i) - 1 % n == 0) return i
        i = i + 1
    }

}
/*
def cycle_length(n):
    i = 1
    if n % 2 == 0: return cycle_length(n / 2)
    if n % 5 == 0: return cycle_length(n / 5)
    while True:
        if (pow(10, i) - 1) % n == 0: return i
        else: i = i + 1

m = 0
n = 0
for d in xrange(1,1000):
    c = cycle_length(d)
    if c > m:
        m = c
        n = d

print n
*/

m = 0
n = 0
for (d in 1G..1000G) {
    c = cycleLength(d)
    if (c > m) {
        m = c
        n = d
    }
}
println "==> $n"